/*********************
  *线程不安全的Buffer
  *自动扩容，可复用Buffer
  *created by dirkcai
  ********************/
#ifndef BUFFER_H
#define BUFFER_H

//offset < limit <= len
//offset指向当前活动的位置(index)
//limit指向已使用的当前容量
class Buffer
{
public:
	Buffer( const int len=1024);
	Buffer( const Buffer & buf );
	~Buffer();
	Buffer & operator =( const Buffer & buf );
	int GetByPos(int index);
	int GetByteBufferCopy(char * psOut, int &iLen);
	char * GetByteBuffer();
	char * GetRemainByteBuffer();
	int Clear();
	int Append(char c);
	int Append(const char * psSrc, const int iLen);
	int SetOffset(int index);
	int SetLimit( int iLimit );
	int GetOffset();
	int GetLimit();
	int GetRemainLen();
	int GetCapability();
private:
	int InsureSize(int len);
public:
	static const int GETC_ERROR = 128;
private:
	char * m_psBuf;
	int m_iLen;
	int m_iLimit;
	int m_iOffset;
};

#endif
